package com.gilight.base.controller;

import com.gilight.base.base.ResultEntity;
import com.gilight.base.properties.UnimallMapAppProperties;
import com.gilight.base.service.CodeGeneratorService;
import com.gilight.base.util.RetrofitUtil;
import com.gilight.base.wechart.http.IMap;
import com.gilight.base.wechart.http.IPersonal;
import com.gilight.base.wechart.model.CodeSession;
import com.gilight.base.wechart.model.MapAddr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import retrofit2.Call;
import retrofit2.Retrofit;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/web/map/qq")
public class QQMapController {
    @Autowired
    private CodeGeneratorService codeGeneratorService;

    @Autowired
    private UnimallMapAppProperties unimallMapAppProperties;
    @RequestMapping(value = "/geo-coder-f", method = {RequestMethod.GET})
    public ResultEntity<Map<String,Object>> generatef(String location
            , String key
            , @RequestParam(defaultValue = "1" ,required = false) Integer get_poi) {
        Retrofit retrofit = RetrofitUtil.QQMapBuile();
        IMap iMap = retrofit.create(IMap.class);
        ResultEntity resultEntity = new ResultEntity();
        try {

            Call<MapAddr> responseCallCodeSession = iMap.fGeo(location,unimallMapAppProperties.getMapKey(),get_poi);

            MapAddr mapAddr = responseCallCodeSession.execute().body();
            resultEntity.setStatus(mapAddr.getStatus());
            resultEntity.setData(mapAddr);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }
    @RequestMapping(value = "/geo-coder-z", method = {RequestMethod.GET})
    public ResultEntity<Map<String,Object>> generatez(String address
            , String key) {
        Retrofit retrofit = RetrofitUtil.QQMapBuile();
        IMap iMap = retrofit.create(IMap.class);
        ResultEntity resultEntity = new ResultEntity();
        try {

            Call<MapAddr> responseCallCodeSession = iMap.zGeo(address,unimallMapAppProperties.getMapKey());
            MapAddr mapAddr = responseCallCodeSession.execute().body();
            resultEntity.setStatus(mapAddr.getStatus());
            resultEntity.setData(mapAddr);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }
}
